<?php
/**
 * 周舟 hzboye010@163.com
 * addby sublime snippets
 */
namespace Common\Api;

use Common\Api\Api;
use Admin\Model\GamePrizeModel;

class GamePrizeApi extends Api{

    const FIND      = "Common/GamePrize/getInfo";
    const COUNT     = "Common/GamePrize/count";
    const SAVE      = "Common/GamePrize/save";
    const SAVEBYID  = "Common/GamePrize/saveByID";
    const ADD       = "Common/GamePrize/add";
    const DEL       = "Common/GamePrize/delete";
    const GET_PRIZE = "Common/GamePrize/getPrize";
    const FINDALL   = "Common/GamePrize/queryNoPaging";

    protected function _init(){
        $this -> model = new GamePrizeModel();
    }

    /**
     * get prizes by the condition
     * @param  [type] $where  	condition
     * @return [json]        		[api data]
     */
    public function getPrize($where,$order='sort asc'){
      $result = $this -> model -> alias('g')
            ->join(C('DB_PREFIX').'user_picture p ON g.prize_icon = p.id')
            ->field('g.*,p.path')->limit(8)
            ->order($order)
            ->where($where)->select();
      if (false === $result) {
        return $this -> apiReturnErr($this -> model -> getDbError());
      } else {
        // $r = array();
        //  foreach ($result as $k => $v) {
        //    $r['']
        //  }
        return $this -> apiReturnSuc($result);
      }
    }
}